<?php

namespace App\Models;
use Str;

class Article extends Base
{
  public static function getIdsGivenSearchWord(string $wd): array
    {
        if (trim($wd) === '') {
            return [];
        }

        // 如果 SCOUT_DRIVER 为 null 则使用 sql 搜索
        if (Str::isNull(config('scout.driver'))) {
            return self::where('title', 'like', "%$wd%")
                ->orWhere('description', 'like', "%$wd%")
                ->orWhere('markdown', 'like', "%$wd%")
                ->pluck('id')
                ->toArray();
        }
        }
        public function tags()
    {
        return $this->belongsToMany(Tag::class, 'article_tags');
    }
    public function category()
    {
        return $this->belongsTo(Category::class);
    }
}
